<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
 <head>
  <meta http-equiv="content-type" content="text/html; charset=UTF-8">
  <title>The Set class</title>
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-base.css" />
<link media="all" rel="stylesheet" type="text/css" href="styles/03e73060321a0a848018724a6c83de7f-theme-medium.css" />

 </head>
 <body class="docs"><div class="navbar navbar-fixed-top">
  <div class="navbar-inner clearfix">
    <ul class="nav" style="width: 100%">
      <li style="float: left;"><a href="ds-pair.toarray.html">« Ds\Pair::toArray</a></li>
      <li style="float: right;"><a href="ds-set.add.html">Ds\Set::add »</a></li>
    </ul>
  </div>
</div>
<div id="breadcrumbs" class="clearfix">
  <ul class="breadcrumbs-container">
    <li><a href="index.html">PHP Manual</a></li>
    <li><a href="book.ds.html">Data Structures</a></li>
    <li>The Set class</li>
  </ul>
</div>
<div id="layout">
  <div id="layout-content"><div id="class.ds-set" class="reference">

 <h1 class="title">The Set class</h1>
 

 <div class="partintro"><p class="verinfo">(No version information available, might only be in Git)</p>


  <div class="section" id="ds-set.intro">
   <h2 class="title">简介</h2>
   <p class="para">
    A Set is a sequence of unique values. This implementation uses the same hash
    table as <span class="classname"><strong class="classname">Ds\Map</strong></span>, where values are used as keys and the
    mapped value is ignored.
   </p>
  </div>



<div class="section" id="ds-set.strengths">
    <h2 class="title">Strengths</h2>
    <p class="para">
        <ul class="simplelist">
            <li class="member">Values can be any type, including objects.</li>
            <li class="member">Supports array syntax (square brackets).</li>
            <li class="member">Insertion order is preserved.</li>
            <li class="member">Automatically frees allocated memory when its size drops low enough.</li>
            <li class="member">
                <span class="function"><strong>add()</strong></span>,
                <span class="function"><strong>remove()</strong></span> and
                <span class="function"><strong>contains()</strong></span> are all O(1).
            </li>
        </ul>
   </p>
</div>

<div class="section" id="ds-set.weaknesses">
    <h2 class="title">Weaknesses</h2>
    <p class="para">
        <ul class="simplelist">
            <li class="member">Doesn’t support
                <span class="function"><strong>push()</strong></span>,
                <span class="function"><strong>pop()</strong></span>,
                <span class="function"><strong>insert()</strong></span>,
                <span class="function"><strong>shift()</strong></span>, or
                <span class="function"><strong>unshift()</strong></span>.
            </li>
            <li class="member">
                <span class="function"><strong>get()</strong></span> is O(n) if there are deleted values
                in the buffer before the accessed index, O(1) otherwise.
            </li>
        </ul>
   </p>
</div>

  <div class="section" id="ds-set.synopsis">
   <h2 class="title">类摘要</h2>


   <div class="classsynopsis">
    <div class="ooclass"></div>


    <div class="classsynopsisinfo">
     <span class="ooclass">
      <span class="modifier">class</span> <strong class="classname">Ds\Set</strong>
     </span>

     <span class="oointerface"><span class="modifier">implements</span> 
       <strong class="interfacename">Ds\Collection</strong></span><span class="oointerface">,  <a href="class.arrayaccess.html" class="interfacename">ArrayAccess</a></span> {</div>

    <div class="classsynopsisinfo classsynopsisinfo_comment">/* Constants */</div>
    <div class="fieldsynopsis">
     <span class="modifier">const</span>
     <span class="type">int</span>
      <var class="fieldsynopsis_varname"><a href="class.ds-set.html#ds-set.constants.min-capacity"><var class="varname">MIN_CAPACITY</var></a></var><span class="initializer"> = 16</span>;</div>


    <div class="classsynopsisinfo classsynopsisinfo_comment">/* 方法 */</div>
    <div class="methodsynopsis dc-description">
   <span class="modifier">public</span> <span class="methodname"><a href="ds-set.add.html" class="methodname">add</a></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">...$values</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.allocate.html" class="methodname">allocate</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$capacity</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.capacity.html" class="methodname">capacity</a></span>(): <span class="type">int</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.clear.html" class="methodname">clear</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.contains.html" class="methodname">contains</a></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">...$values</code></span>): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.copy.html" class="methodname">copy</a></span>(): <span class="type"><a href="class.ds-set.html" class="type Ds\Set">Ds\Set</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.diff.html" class="methodname">diff</a></span>(<span class="methodparam"><span class="type"><a href="class.ds-set.html" class="type Ds\Set">Ds\Set</a></span> <code class="parameter">$set</code></span>): <span class="type"><a href="class.ds-set.html" class="type Ds\Set">Ds\Set</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.filter.html" class="methodname">filter</a></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="class.ds-set.html" class="type Ds\Set">Ds\Set</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.first.html" class="methodname">first</a></span>(): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.get.html" class="methodname">get</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$index</code></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.intersect.html" class="methodname">intersect</a></span>(<span class="methodparam"><span class="type"><a href="class.ds-set.html" class="type Ds\Set">Ds\Set</a></span> <code class="parameter">$set</code></span>): <span class="type"><a href="class.ds-set.html" class="type Ds\Set">Ds\Set</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.isempty.html" class="methodname">isEmpty</a></span>(): <span class="type">bool</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.join.html" class="methodname">join</a></span>(<span class="methodparam"><span class="type">string</span> <code class="parameter">$glue</code><span class="initializer"> = ?</span></span>): <span class="type">string</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.last.html" class="methodname">last</a></span>(): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.merge.html" class="methodname">merge</a></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$values</code></span>): <span class="type"><a href="class.ds-set.html" class="type Ds\Set">Ds\Set</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.reduce.html" class="methodname">reduce</a></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$callback</code></span>, <span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">$initial</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.remove.html" class="methodname">remove</a></span>(<span class="methodparam"><span class="type"><a href="language.types.declarations.html#language.types.declarations.mixed" class="type mixed">mixed</a></span> <code class="parameter">...$values</code></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.reverse.html" class="methodname">reverse</a></span>(): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.reversed.html" class="methodname">reversed</a></span>(): <span class="type"><a href="class.ds-set.html" class="type Ds\Set">Ds\Set</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.slice.html" class="methodname">slice</a></span>(<span class="methodparam"><span class="type">int</span> <code class="parameter">$index</code></span>, <span class="methodparam"><span class="type">int</span> <code class="parameter">$length</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="class.ds-set.html" class="type Ds\Set">Ds\Set</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.sort.html" class="methodname">sort</a></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$comparator</code><span class="initializer"> = ?</span></span>): <span class="type"><span class="type void">void</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.sorted.html" class="methodname">sorted</a></span>(<span class="methodparam"><span class="type"><a href="language.types.callable.html" class="type callable">callable</a></span> <code class="parameter">$comparator</code><span class="initializer"> = ?</span></span>): <span class="type"><a href="class.ds-set.html" class="type Ds\Set">Ds\Set</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.sum.html" class="methodname">sum</a></span>(): <span class="type"><span class="type">int</span>|<span class="type">float</span></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.toarray.html" class="methodname">toArray</a></span>(): <span class="type">array</span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.union.html" class="methodname">union</a></span>(<span class="methodparam"><span class="type"><a href="class.ds-set.html" class="type Ds\Set">Ds\Set</a></span> <code class="parameter">$set</code></span>): <span class="type"><a href="class.ds-set.html" class="type Ds\Set">Ds\Set</a></span></div>
<div class="methodsynopsis dc-description"><span class="modifier">public</span> <span class="methodname"><a href="ds-set.xor.html" class="methodname">xor</a></span>(<span class="methodparam"><span class="type"><a href="class.ds-set.html" class="type Ds\Set">Ds\Set</a></span> <code class="parameter">$set</code></span>): <span class="type"><a href="class.ds-set.html" class="type Ds\Set">Ds\Set</a></span></div>

   }</div>


  </div>


  <div class="section" id="ds-set.constants">
   <h2 class="title">预定义常量</h2>
   <dl>

    
     <dt id="ds-set.constants.min-capacity"><strong><code>Ds\Set::MIN_CAPACITY</code></strong></dt>

     <dd>

      <p class="para"/>
     </dd>

    

   </dl>

  </div>


  <div class="section">
   <h2 class="title">更新日志</h2>
   <p class="para">
    <table class="doctable informaltable">
     
      <thead>
       <tr>
        <th>版本</th>
        <th>说明</th>
       </tr>

      </thead>

      <tbody class="tbody">
       <tr>
        <td>PECL ds 1.3.0</td>
        <td>
         The class now implements <span class="classname"><a href="class.arrayaccess.html" class="classname">ArrayAccess</a></span>.
        </td>
       </tr>

      </tbody>
     
    </table>

   </p>
  </div>

 </div>

 












































































































































































































<h2>目录</h2><ul class="chunklist chunklist_reference"><li><a href="ds-set.add.html">Ds\Set::add</a> — Adds values to the set</li><li><a href="ds-set.allocate.html">Ds\Set::allocate</a> — Allocates enough memory for a required capacity</li><li><a href="ds-set.capacity.html">Ds\Set::capacity</a> — Returns the current capacity</li><li><a href="ds-set.clear.html">Ds\Set::clear</a> — Removes all values</li><li><a href="ds-set.construct.html">Ds\Set::__construct</a> — Creates a new instance</li><li><a href="ds-set.contains.html">Ds\Set::contains</a> — Determines if the set contains all values</li><li><a href="ds-set.copy.html">Ds\Set::copy</a> — Returns a shallow copy of the set</li><li><a href="ds-set.count.html">Ds\Set::count</a> — Returns the number of values in the set</li><li><a href="ds-set.diff.html">Ds\Set::diff</a> — Creates a new set using values that aren't in another set</li><li><a href="ds-set.filter.html">Ds\Set::filter</a> — Creates a new set using a callable to
    determine which values to include</li><li><a href="ds-set.first.html">Ds\Set::first</a> — Returns the first value in the set</li><li><a href="ds-set.get.html">Ds\Set::get</a> — Returns the value at a given index</li><li><a href="ds-set.intersect.html">Ds\Set::intersect</a> — Creates a new set by intersecting values with another set</li><li><a href="ds-set.isempty.html">Ds\Set::isEmpty</a> — Returns whether the set is empty</li><li><a href="ds-set.join.html">Ds\Set::join</a> — Joins all values together as a string</li><li><a href="ds-set.jsonserialize.html">Ds\Set::jsonSerialize</a> — Returns a representation that can be converted to JSON</li><li><a href="ds-set.last.html">Ds\Set::last</a> — Returns the last value in the set</li><li><a href="ds-set.merge.html">Ds\Set::merge</a> — Returns the result of adding all given values to the set</li><li><a href="ds-set.reduce.html">Ds\Set::reduce</a> — Reduces the set to a single value using a callback function</li><li><a href="ds-set.remove.html">Ds\Set::remove</a> — Removes all given values from the set</li><li><a href="ds-set.reverse.html">Ds\Set::reverse</a> — Reverses the set in-place</li><li><a href="ds-set.reversed.html">Ds\Set::reversed</a> — Returns a reversed copy</li><li><a href="ds-set.slice.html">Ds\Set::slice</a> — Returns a sub-set of a given range</li><li><a href="ds-set.sort.html">Ds\Set::sort</a> — Sorts the set in-place</li><li><a href="ds-set.sorted.html">Ds\Set::sorted</a> — Returns a sorted copy</li><li><a href="ds-set.sum.html">Ds\Set::sum</a> — Returns the sum of all values in the set</li><li><a href="ds-set.toarray.html">Ds\Set::toArray</a> — Converts the set to an array</li><li><a href="ds-set.union.html">Ds\Set::union</a> — Creates a new set using values from the current instance and another set</li><li><a href="ds-set.xor.html">Ds\Set::xor</a> — Creates a new set using values in either the current instance or in another set, but not in both</li></ul>
</div>
</div></div></body></html>